package com.example.a10928.weifriend.view;

import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.a10928.weifriend.R;

public class TitleLayout extends RelativeLayout {


    TextView tv_title;

    public TitleLayout(Context context) {
        super(context);
    }

    public TitleLayout(Context context, AttributeSet attrs) {
        super(context, attrs);

        LayoutInflater.from(context).inflate(R.layout.layout_title, this);
        ImageView iv=(ImageView)findViewById(R.id.iv_back);
        tv_title = (TextView) findViewById(R.id.tv_title);


        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TitleLayout);
        String title = typedArray.getString(R.styleable.TitleLayout_TitleLayout_tv);
        if(title==null){
            title="";
        }

        typedArray.recycle();//释放资源

        tv_title.setText(title);

        iv.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ((Activity)context).finish();
            }
        });


    }


    public void setTitle(String title){
        tv_title.setText(title);
    }


}
